//
//  ChapterDetailViewController.m
//  VNBooks
//
//  Created by Steve Hai on 12/25/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "ChapterDetailViewController.h"
#import "VNBooksAppDelegate.h"
#import "Chapter.h"
#import "ChapterExtension.h"

@implementation ChapterDetailViewController
@synthesize chapterWebView;
@synthesize titleView;
@synthesize titleImageView;
@synthesize chapterNameLabel;
@synthesize backButon;
@synthesize likeButton;
@synthesize chapter;

- (IBAction)backButtonPressed{
    [mainAppDelegate.mainNavController popViewControllerAnimated:YES];
}

- (IBAction)like:(id)sender{
    likeButton.selected = !likeButton.selected;
    [Chapter updateFavoriteStatus:1 favorite:likeButton.selected];
}

- (void)loadContentWithChapterId:(NSNumber *)chapterId
{
    chapter = [[Chapter alloc] init];
    chapter = [Chapter getChapter:[chapterId intValue]];
    NSLog(@"content: %@", chapter.content);
    [chapterWebView loadHTMLString:chapter.content baseURL:nil];
}

- (void)dealloc{
    [chapterWebView release];
    [titleView release];
    [titleImageView release];
    [chapterNameLabel release];
    [backButon release];
    [likeButton release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //Init Code
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    //[chapterWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.co.jp/"]]];
    // Do any additional setup after loading the view from its nib.
}

    
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
